$('.nav-tabs-course li').click(function(){
    $('.nav-tabs-course li').removeClass('active');
    $(this).addClass('active');
    if($(this).hasClass('course_add')){
        $('.course_class').css('display','block');
        $('.course_section').css('display','none');
        $('.course_class_define').css('display','none');
    }else if($(this).hasClass('course_define')){
        $('.course_class').css('display','none');
        $('.course_section').css('display','none');
        $('.course_class_define').css('display','block');
    }else{
        $('.course_class').css('display','none');
        $('.course_section').css('display','block');
        $('.course_class_define').css('display','none');
    }
});
var courseArr = ['第一节','第二节','第三节','第四节','第五节','第六节','第七节','第八节','第九节','第十节','第十一节','第十二节','第十三节','第十四节','第十五节','第十六节','第十七节','第十八节','第十九节','第二十节','第二十一节','第二十二节','第二十三节','第二十四节','第二十五节','第二十六节','第二十七节','第二十八节','第二十九节','第三十节','第三十一节','第三十二节','第三十三节','第三十四节','第三十五节','第三十六节','第三十七节','第三十八节','第三十九节','第四十节'];

var courseTrans = ['one','two','three','four','five','six','seven','eight','nine','ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen','twenty','twentyOne','twentyTwo','twentyThree','twentyFour','twentyFive','twentySix','twentySeven','twentyEight','twentyNine','thirty','thirtyOne','thirtyTwo','thirtyThree','thirtyFour','thirtyFive','thirtySix','thirtySeven','thirtyEight','thirtyNine','forty'];

function addNewCourse(obj){
    var num = $(obj).attr('data-name');
    var courseName = 'course_name_'+num;
    var courseAddress = 'course_address_'+num;
    var html = '<div class="row course_content"><div class="col-sm-5"><div class="input-group"><span class="input-group-btn"><button class="btn btn-default" type="button">课程名称</button></span><input type="text" class="form-control" name="'+courseName+'[]" style="width:230px;" placeholder=""></div></div><div class="col-sm-5"><div class="input-group"><span class="input-group-btn"><button class="btn btn-default" type="button">课程地址</button></span><input type="text" class="form-control" name="'+courseAddress+'[]" style="width:260px;" placeholder=""></div></div></div>';
    $(obj).parent().prev().find('.create_course').append(html);
}

function addCourseClass(obj){
    var length = $('.course_total_add .section_num').length;
    var count = length;
    var courseName = 'course_name_'+courseTrans[count];
    var courseAddress = 'course_address_'+courseTrans[count];
    var course_section = 'course_section_'+courseTrans[count];
    var html = '<div class="row section_num"><div class="col-sm-2"><div class="form-group"><label for="inputEmail3" class="control-label"><span>'+courseArr[count]+'：</span></label></div></div><div class="col-sm-10 create_course"><div class="row course_content"><div class="col-sm-5"><div class="input-group"><span class="input-group-btn"><button class="btn btn-default" type="button">小节标题</button></span><input type="text" class="form-control" name="'+course_section+'" style="width:230px;" placeholder=""></div></div></div></div></div><div class="row"><div class="col-sm-2"><div class="form-group"><label for="inputEmail3" class="control-label"><span></span></label></div></div><div class="col-sm-10 create_course"><div class="row course_content"><div class="col-sm-5"><div class="input-group"><span class="input-group-btn"><button class="btn btn-default" type="button">课程名称</button></span><input type="text" class="form-control" style="width:230px;" name="'+courseName+'[]" placeholder=""></div></div><div class="col-sm-5"><div class="input-group"><span class="input-group-btn"><button class="btn btn-default" type="button">课程地址</button></span><input type="text" name="'+courseAddress+'[]"class="form-control" style="width:260px;" placeholder=""></div></div></div></div></div><div clas="row"><button type="button" class="btn btn-primary" data-name="'+courseTrans[count]+'" onclick="addNewCourse(this);" data-toggle="modal" data-target="#exampleModal"><i class="fa fa-plus"></i>新增</button></div>';

    $("#myTabContent").find('.course_total_add').append(html);
}

function selectAuthor(obj){
    var page = $(obj).attr('data-page');
    var name = $('#authorName').val();

    var data = {page:page,name:name};
    $.ajax({
        url:'/author/choose',
        data:data,
        type:'GET',
        dataType:'json',
        success:function(res){
            if(res.code == 0){
                $('#myModal .modal-body').html(res.body);
                $('#myModal').modal('show');
            }

        }
    });
    $('#myModal').modal('show')
}

function selectCourse(obj){
    var page = $(obj).attr('data-page');
    var title = $('#courseTitle').val();
    var data = {page:page,title:title};
    $.ajax({
        url:'/course/choose',
        data:data,
        type:'GET',
        dataType:'json',
        success:function(res){
            if(res.code == 0){
                $('#myModal .modal-body').html(res.body);
                $('#myModal').modal('show');
            }
        }
    });
}
function courseChecked(obj){
    var class_id = $(obj).attr('data-id');
    var name = $(obj).attr('data-name');
    $("input[name='courseId']").val(class_id);
    $('#courseId').text(name);
    $('#myModal').modal('hide');
    $('#courseTitle').val('');
}
function chooseOk(obj){

    var user_id = $(obj).attr('data-id');
    var name = $(obj).attr('data-name');
    $("input[name='author']").val(user_id);
    $('#userName').text(name);
    $('#myModal').modal('hide');
    $('#authorName').val('');
}